<template>
  <div style="height:100%;width:100%;position:relative;" ref="maindev">
      <div class="pagetop" ref="buttondiv" :style="pagetopstyle">
          <div style="width: 100%">
              <table>
                  <tr>
                      <td align="right">报告日期</td>
                      <td>
                          <el-date-picker v-model="searchParam.startdt" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" :clearable="false" style="width: 130px"></el-date-picker> 至
                          <el-date-picker v-model="searchParam.enddt" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" :clearable="false" style="width: 130px"></el-date-picker>
                      </td>
                      <td>报告单元</td>
                      <td>
                          <rm-ddl-rptunit prgno="LIS610" v-model="searchParam.rptunitid" width="100%" defaultflag="1" clearable @change="rptunitChange"></rm-ddl-rptunit>
                      </td>
                      <td style="color: #fd5645;font-weight: 600;">报告项目</td>
                      <td>
                          <rm-ddl-rptitem prgno="LIS661" isAllRpt ="1" v-model="searchParam.rpt_itemcode" width="100%" :appendtobody="true" :rptunitid="searchParam.rptunitid" @change="rptitemChange"></rm-ddl-rptitem>
                      </td>
                      <td align="right">检验结果</td>
                      <td style="text-align:left">
                          <el-input v-model="searchParam.result_min" style="width:100px" @focus="Focus($event)"></el-input>
                      </td>
                      <td style="color:#606266">——</td>
                      <td colspan="2" style="text-align:left">
                          <el-input v-model="searchParam.result_max" style="width:100px" @focus="Focus($event)"></el-input>
                      </td>
                      <td>&nbsp;</td>
                  </tr>
                  <tr>
                      <td>姓名</td>
                      <td>
                          <el-tooltip v-if="searchParam.pat_name_mh" class="item" effect="dark" content="模糊查询" placement="top-end">
                              <el-input size="small" class="ismh1" style="width:calc( 100% - 70px );background-color:#ffffff29!important" v-model="searchParam.pat_name"></el-input>
                          </el-tooltip>
                          <el-input v-if="!searchParam.pat_name_mh" size="small" :ismh='searchParam.pat_name_mh? "1" :"0" ' style="width:calc( 100% - 70px );background-color:#ffffff29" v-model="searchParam.pat_name"></el-input>
                          &nbsp;
                          <el-checkbox v-model="searchParam.pat_name_mh" @focus="Focus($event)">模糊</el-checkbox>
                          <!-- <el-checkbox v-model="searchParam.pat_name_re" @focus="Focus($event)">剔除姓名</el-checkbox> -->
                      </td>
                      <td>病人类型</td>
                      <td>
                          <rm-ddl-common ref="txtpattype" datatype="seccode" kindno="PT" dataname="病人类型" v-model="searchParam.pat_typecode" width="100%" :readonly="true" :clearable="true" @change="pattypeChange"></rm-ddl-common>
                      </td>
                      <td>性别
                      </td>
                      <td>
                          <el-select v-model="searchParam.pat_sex" placeholder="请选择" style="width:100%">
                              <el-option key="0" label="全部" value="0"></el-option>
                              <el-option key="1" label="男" value="1"></el-option>
                              <el-option key="2" label="女" value="2"></el-option>
                          </el-select>
                      </td>
                      <td align="right">年龄</td>
                      <td style="text-align:left">
                          <el-input size="small" style="width:100px" v-model="searchParam.agemin" oninput="value=value.replace(/[^\-?\d.]/g,'')" @focus="Focus($event)"></el-input>
                      </td>
                      <td style="color:#606266">——</td>
                      <td  style="text-align:left">
                          <el-input size="small" style="width:100px" v-model="searchParam.agemax" oninput="value=value.replace(/[^\-?\d.]/g,'')" @focus="Focus($event)"></el-input>
                      </td>
                  </tr>
                  <tr v-show="Showflag">
                      <td>审核状态</td>
                      <td>
                          <el-select v-model="searchParam.rechkflag" placeholder="请选择" style="width:100%">
                              <el-option key="all" label="全部" value="all"></el-option>
                              <el-option key="0" label="未审核" value="0"></el-option>
                              <el-option key="1" label="已审核" value="1"></el-option>
                          </el-select>
                      </td>
                      <td>样本号</td>
                      <td>
                          <el-input size="small" style="width:100%;" placeholder="输入如1,2,5-8等格式" v-model="searchParam.sampleno" @focus="Focus($event)"></el-input>
                      </td>
                      <td>样本类型</td>
                      <td>
                          <rm-ddl-common ref="ddlspecimen" datatype="specimen" dataname="样本类型" v-model="searchParam.specimen_code" width="100%" @change="specimenChange"></rm-ddl-common>
                      </td>
                      <td>专家评语</td>
                      <td colspan="3" rowspan="3">
                          <el-tooltip class="item" effect="dark" content="模糊查询" placement="top-end">
                              <el-input style="background-color:#a3c1f429" type="textarea" :rows="3" v-model="searchParam.result_txt" @focus="Focus($event)"></el-input>
                          </el-tooltip>
                      </td>
                      <td style="text-align:left">
                          <el-checkbox v-model="searchParam.pat_sex_outflag">无性别</el-checkbox>
                      </td>
                  </tr>
                  <tr v-show="Showflag">
                      <td>病区</td>
                      <td>
                          <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="searchParam.req_wardno" width="100%" @change="reqwardChange"></rm-ddl-common>
                      </td>
                      <td>检验医生</td>
                      <td>
                          <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchParam.report_user" width="100%" @change="reportuserChange"></rm-ddl-common>
                      </td>
                      <td>申请医生</td>
                      <td>
                          <rm-ddl-common datatype="doctor" dataname="送检医生" v-model="searchParam.req_docno" width="100%" @change="reqdocChange"></rm-ddl-common>
                      </td>
                      <td></td>
                      <td>
                          <el-checkbox v-model="searchParam.pat_name_outflag">无姓名</el-checkbox>
                      </td>
                  </tr>
                  <tr v-show="Showflag">
                      <td>仪器</td>
                      <td>
                          <rm-ddl-instrument width="100%" v-model="searchParam.instrid" prgno="LIS661" :clearable="true" @change="instrChange"></rm-ddl-instrument>
                      </td>
                      <td>临床诊断</td>
                      <td>
                          <el-tooltip class="item" effect="dark" content="模糊查询" placement="top-end">
                              <el-input size="small" ismh="1" style="width:100%;" v-model="searchParam.pat_diag" @focus="Focus($event)"></el-input>
                          </el-tooltip>
                      </td>
                      <td>备注</td>
                      <td>
                          <el-tooltip class="item" effect="dark" content="模糊查询" placement="top-end">
                              <el-input size="small" ismh="1" style="width:100%;" v-model="searchParam.report_comm" @dblclick.native="reportcommDlg=true" placeholder="手工输入 | 双击开窗" @focus="Focus($event)"></el-input>
                          </el-tooltip>
                      </td>
                      <td></td>
                      <td>
                          <el-checkbox v-model="searchParam.result_outflag">正常结果 </el-checkbox>
                      </td>
                  </tr>
              </table>
              <div style="width:100%;text-align:right;padding-right:5px;">
                  <el-link :underline="false" @click="OpenMoreSel">{{ Showflag?"收起▲":"展开▼" }}</el-link>&nbsp;&nbsp;
                  <el-button icon="el-icon-search" type="primary" @click="btnQuery" v-has="'PINQUERY'">查询</el-button>
                  <el-button icon="el-icon-circle-check" @click="bTNcheckNormal">选择正常</el-button>
                  <el-button icon="el-icon-edit-outline" @click="btnCalculate(0)">计算</el-button>
                  <!-- <el-button icon="el-icon-edit-outline" @click="btnHelp()">使用方法</el-button> -->
                  <!-- <el-button icon="el-icon-upload2" @click="btnCalculate">导出</el-button> -->
                  <!-- <el-button icon="el-icon-printer" @click="btnCalculate">打印</el-button> -->
                  <el-button @click="setExportColumn">导出列设置</el-button>
                  <el-button icon="el-icon-upload2" @click.native="btnExport()">导出</el-button>
                  <el-button icon="el-icon-close" type="warning" @click="btnExc">退出</el-button>
              </div>
          </div>
      </div>
      <div class="pagecenter" :style="pagecenter">
          <div class="middle-center" ref="xTableDiv">
              <vxe-table ref="xTable" :data="tableData" :loading="loading" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{trigger: 'click', mode: 'cell'}" border fit :height="reportheight" header-align="center" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe :row-class-name="rowClassName" :cell-class-name="cellClassName" @current-change="currentChangeEvent" highlight-current-row show-footer @cell-dblclick="xTableDblEvent">
                  <vxe-table-column field="pat_no" sortable title="病人号" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_name" sortable title="姓名" width="80" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_sexname" sortable title="性别" width="50" show-overflow align=center></vxe-table-column>
                  <vxe-table-column field="pat_nationna" align="center" sortable title="民族" width="80" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_agestr" align="center" sortable title="年龄" width="40" show-overflow></vxe-table-column>
                  <vxe-table-column field="rptunitname" title="报告单元" width="130" header-align="center" class="rowspantop"></vxe-table-column>
                  <vxe-table-column align="center" field="sampledate" sortable title="标本日期" width="70" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
                  <vxe-table-column field="sampleno" title="样本号" width="80" header-align="center">
                  </vxe-table-column>
                  <vxe-table-column field="itemcode_en" sortable title="英文缩写" width="80" show-overflow></vxe-table-column>
                  <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="220" show-overflow></vxe-table-column>
                  <vxe-table-column field="cp_selection" title="选择" width="40px" align="center">
                      <template v-slot:header="{ column }">
                          <el-checkbox v-model="selectall" @change="ChkAll($event)"></el-checkbox>
                      </template>
                      <template v-slot="{ row  }">
                          <el-checkbox v-model="row.cp_selection" @change="ChkEven(row)" true-label="1" false-label="0"></el-checkbox>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="result_str" sortable title="检测结果" width="80" show-overflow> <template v-slot="{ row }">
                          <div :style="{
                              background: row.cp_resultbackgroundcolor,
                              color: row.cp_resultcolor
                          }" style="padding:0px 10px">
                              {{ row.result_str }}
                          </div>
                      </template></vxe-table-column>
                  <vxe-table-column field="result_unit" sortable title="单位" width="70" show-overflow></vxe-table-column>
                  <vxe-table-column field="result_ref" sortable title="参考值" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="result_flag" align="center" sortable title="结果标志" width="60" show-overflow></vxe-table-column>
                  <vxe-table-column field="specimen_name" align="center" sortable title="样本类型" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="req_dept" sortable title="申请科室" width="150" show-overflow></vxe-table-column>
                  <vxe-table-column field="req_ward" sortable title="病人病区" width="120" show-overflow></vxe-table-column>
                  <vxe-table-column field="req_bedno" align="center" sortable title="床号" width="70" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_typename" sortable title="病人类型" width="80" show-overflow></vxe-table-column>
                  <vxe-table-column field="create_dt" sortable title="创建时间" width="140" show-overflow></vxe-table-column>
                  <vxe-table-column field="barcode" sortable title="条码号" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="req_doc" align="center" sortable title="申请医生" width="70" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_diag" sortable title="临床诊断" width="250" show-overflow></vxe-table-column>
                  <vxe-table-column field="report_user" align="center" sortable title="检验医生" width="70" show-overflow></vxe-table-column>
                  <vxe-table-column field="orig_result_num" sortable title="原始数值结果" width="150" show-overflow></vxe-table-column>
                  <vxe-table-column field="test_info" sortable title="上机信息" width="120" show-overflow></vxe-table-column>
                  <vxe-table-column field="sample_archive" sortable align="center" title="归档位置" width="150" show-overflow>
                  </vxe-table-column>
                  <vxe-table-column field="rechk_dt" align="center" sortable title="审核时间" width="120" show-overflow></vxe-table-column>
                  <vxe-table-column field="rechk_user" align="center" sortable title="审核医生" width="60" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_idcardno" align="center" sortable title="身份证/护照号" width="200" show-overflow></vxe-table-column>
                  <vxe-table-column field="result_txt" sortable title="大文本结果" width="130" show-overflow></vxe-table-column>
                  <vxe-table-column field="report_comm" sortable title="报告单备注" width="150" show-overflow></vxe-table-column>
                  <vxe-table-column field="pat_id" sortable title="病人ID" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="reportid" sortable title="报告ID" width="160" show-overflow></vxe-table-column>
              </vxe-table>
          </div>
      </div>
      <el-dialog width="960px" height="450px" :append-to-body="true" :close-on-click-modal="false" title="计算" :visible.sync="bCalcDlg" :destroy-on-close="true">
          <div style="height:35px;width:100%">
              <div style="height:100%;width:65.6%;float:left;text-align: left;font-size: 16px;color:#000;font-weight: 500;">
                  <p style="font-size: 16px;color:#000;font-weight: 600;padding:3
px;">结果列表</p>
              </div>
              <div style="height:100%;width:34.3%;float:right;text-align: right;">
                  <el-button icon="el-icon-search" type="primary" @click="BtnExport" v-has="'PINQUERY'">导出TXT</el-button>
                  <!-- <el-button icon="el-icon-close" @click="btnCalculate(0)" type="warning">关闭</el-button> -->
              </div>
          </div>
          <div style="height:750px;width:100%">
              <div style="height:100%;float:left;width:66%">
                  <vxe-table ref="xTable1" :data="calcTableData" :loading="loading" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{trigger: 'click', mode: 'cell'}" border fit height="auto" header-align="center" resizable :show-header="false" show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe :row-class-name="rowClassName" align="center">
                      <vxe-table-column :key="item.field" :field="item.field" v-for="item in tableColumn" align="center" :width="item.width" sortable><template v-slot="{row,column}">
                              <div :style="TmpRClassName(row,column)" style="cursor:pointer">
                                  <span>{{row[column.property]}}</span>
                              </div>
                          </template></vxe-table-column>
                  </vxe-table>
              </div>
              <div style="float:right;height:100%;width:33.3%;font-weight:600;border:1px solid #DCDFE6">
                  <table style="height:350px">
                      <col style="width: 10%;" />
                      <col style="width: 40%;" />
                      <col style="width: 10%;" />
                      <col style="width: 40%;" />
                      <tr>
                          <td colspan="4">
                              <el-divider content-position="left" style="font-size: 16px;color:#000;font-weight: 500;">显示规则</el-divider>
                          </td>
                      </tr>
                      <tr style="height:15px"></tr>
                      <tr>
                          <td colspan="2" style="text-align:center;">&lt;1SD</td>
                          <td colspan="2" style="text-align:center;color:#FF8000">&gt;2SD</td>
                      </tr>
                      <tr>
                          <td colspan="2" style="text-align:center;color:rgb(43, 124, 216)">&gt;1SD</td>
                          <td colspan="2" style="text-align:center;color:rgb(240, 70, 48)">&gt;3SD</td>
                      </tr>
                      <tr style="height:15px"></tr>
                      <tr>
                          <td colspan="4">
                              <el-divider content-position="left" style="font-size: 16px;color:#000;font-weight: 500;">二次计算选项</el-divider>
                          </td>
                      </tr>
                      <tr style="height:15px"></tr>
                      <tr>
                          <td colspan="3" style="text-align:right">
                              <el-button icon="el-icon-close" @click="btnCalculate(1)" style="width:130px">剔除大于1SD的数据</el-button>
                          </td>
                          <td>
                              <p style="display: inline;" v-if="del1sd>0">已剔除{{del1sd}}次</p>
                          </td>
                      </tr>
                      <tr>
                          <td colspan="3" style="text-align:right">
                              <el-button icon="el-icon-close" @click="btnCalculate(2)" style="width:130px">剔除大于2SD的数据</el-button>
                          </td>
                          <td>
                              <p style="display: inline;" v-if="del2sd>0">已剔除{{del2sd}}次</p>
                          </td>
                      </tr>
                      <tr>
                          <td colspan="3" style="text-align:right">
                              <el-button icon="el-icon-close" @click="btnCalculate(3)" style="width:130px">剔除大于3SD的数据</el-button>
                          </td>
                          <td>
                              <p style="display: inline;" v-if="del3sd>0">已剔除{{del3sd}}次</p>
                          </td>
                      </tr>
                      <tr style="height:15px"></tr>
                      <td colspan="4">
                          <el-divider content-position="left" style="font-size: 16px;color:#000;font-weight: 500;">统计数值</el-divider>
                      </td>
                      <tr>
                          <td>项目</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.item" readonly></el-input>
                          </td>
                          <td>个数</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.cnt" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>均值</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.avg" readonly></el-input>
                          </td>
                          <td>中位数</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.mid" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>SD</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.sd" readonly></el-input>
                          </td>
                          <td>CV</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.cv" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>最小</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.min" readonly></el-input>
                          </td>
                          <td>最大</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.max" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>0.1%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p0001" readonly></el-input>
                          </td>
                          <td>1%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p0100" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>2.5%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p0250" readonly></el-input>
                          </td>
                          <td>5%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p0500" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>10%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p1000" readonly></el-input>
                          </td>
                          <td>20%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p2000" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>25%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p2500" readonly></el-input>
                          </td>
                          <td>75%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p7500" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>80%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p8000" readonly></el-input>
                          </td>
                          <td>90%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p9000" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>95%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p9500" readonly></el-input>
                          </td>
                          <td>97.5%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p9750" readonly></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td>99%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p9900" readonly></el-input>
                          </td>
                          <td>99.9%</td>
                          <td>
                              <el-input size="small" style="width:100%;" v-model="calcParam.p9990" readonly></el-input>
                          </td>
                      </tr>

                  </table>
              </div>
          </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择备注" :visible.sync="reportcommDlg">
          <rm-pop-common ref="popcom" @change="reportcommchange" @cancel="reportcommDlg=false;" kindno="reportcomm" datatype="seccode"></rm-pop-common>
      </el-dialog>
      <el-dialog width="1300px" height="450px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="LIS661 学术统计 使用说明" :visible.sync="bHelpDlg">
          <div style="width:1250px;height:700px">
              <el-image style="width:100%;" :src="src" ></el-image>
          </div>
      </el-dialog>
      <!--导出列选择-->
      <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false" v-if="chooseColumndialogVisible">
          <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset"></rm-excolsetting>
      </el-dialog>
      <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
  </div>
</template>

<script>
import XE from "xe-utils"; //引入工具类
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
export default {
  name: "LIS661",
  components: { RmExcolsetting },
  data() {
      return {
          src: require("@/assets/img/LIS/LIS6/LIS661.jpg"),
          pattypeOption: [],
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          keyLocalConfig: {
              isArrow: true,
          },
          selectConfig: {
              tigger: "row",
          },
          del1sd: 0,
          del2sd: 0,
          del3sd: 0,
          bCalcDlg: false,
          calcParam: {
              numarr: [],
              item: "",
              cnt: "",
              avg: "",
              sd: "",
              cv: "",
              min: "",
              max: "",
              mid: "",
              p0001: "",
              p0100: "",
              p0250: "",
              p0500: "",
              p1000: "",
              p2000: "",
              p2500: "",
              p7500: "",
              p8000: "",
              p9000: "",
              p9500: "",
              p9750: "",
              p9900: "",
              p9990: "",
          },
          searchParam: {
              startdt: XE.toDateString(new Date(), "yyyy-MM-dd"),
              enddt: XE.toDateString(new Date(), "yyyy-MM-dd"),
              rptunitid: "",
              rpt_itemcode: "",
              result_min: "",
              result_max: "",
              pat_name: "",
              pat_name_mh: false,
              pat_name_re: "",
              pat_typecode: "",
              pat_sex: "0",
              agemin: "",
              agemax: "",
              rechkflag: "1",
              sampleno: "",
              specimen_code: "",
              result_txt: "",
              req_wardno: "",
              report_user: "",
              req_docno: "",
              instrid: "",
              pat_diag: "",
              report_comm: "",
              pat_sex_outflag: "",
              pat_name_outflag: "",
              result_outflag: "",
          },
          numsdarr: [],
          macaddress: "",
          Showflag: false, //展示更多标志
          tableData: [],
          calcTableData: [],
          loading: false,
          selrow: {},
          selectall: false, 
          pagetopstyle: {
              position: "absolute",
              height: "97px",
              width: "100%",
          },
          pagecenter: {
              position: "absolute",
              top: "102px",
              bottom: "0px",
              overflow: "auto",
              width: "100%",
              left: "0px",
          },
          reportcommDlg: false,
          reportheight: "auto",
          calcData: [],
          tableColumn: [],
          bHelpDlg: false,
          chooseColumndialogVisible:false,
          excolPro: "lis661",
          allTableCol:[],
          rptunitname: "",
          rpt_itemname: "",
          pattypename: "",
          specimenname: "",
          reqwardname: "",
          reportusername: "",
          reqdocname: "",
          instrname: "",
      };
  },
  mounted() {
      this.setcalcTableCol();
  this.$refs.excolset.colSettingToDB();
  },
  methods: {
      btnHelp() {
          this.bHelpDlg = true;
      },
      Focus(event) {
          event.currentTarget.select();
      },
      reportcommchange(c, v) {
          this.searchParam.report_comm = v;
          this.reportcommDlg = false;
      },
      BtnExport() {
          if (this.calcParam.numarr.length > 0) {
              let rloading = this.$pub.openLoading(this, "开始导出数据，请稍等！");
              let filestr = "";
              filestr += "项目：" + this.calcParam.item + ",";
              if (this.del1sd > 0) {
                  filestr += "剔除大于1SD次数：" + this.del1sd + ",";
              }
              if (this.del2sd > 0) {
                  filestr += "剔除大于2SD次数：" + this.del3sd + ",";
              }
              if (this.del3sd > 0) {
                  filestr += "剔除大于3SD次数：" + this.del3sd + ",";
              }
              filestr += "个数：" + this.calcParam.cnt + ",";
              filestr += "结果列表：";
              this.calcParam.numarr.forEach((e) => {
                  filestr += e + ",";
              });
              filestr += "均值：" + this.calcParam.avg + ",";
              filestr += "中位数：" + this.calcParam.mid + ",";
              filestr += "SD：" + this.calcParam.sd + ",";
              filestr += "CV：" + this.calcParam.cv + ",";
              filestr += "最小：" + this.calcParam.min + ",";
              filestr += "最大：" + this.calcParam.max + ",";
              filestr += "统计时间：" + XE.toDateString(new Date(), "yyyy-MM-dd HH:ss");
              let filename = "LIS611" + this.searchParam.startdt + "_" + this.searchParam.enddt + "_" + this.searchParam.rpt_itemcode;
              let p = { prgno: "LIS661", filename: filename, filestr: filestr };
              this.$pub.commexport(this, p, filename + ".txt", "text/html;charset=gb2312");
              rloading.close();
          } else {
              this.$alert("请选择需要导出的数据！", "提示");
          }
      },
      setcalcTableCol() {
          this.tableColumn = [];
          for (var i = 0; i < 10; i++) {
              var p = {
                  align: "center",
                  field: "col_" + i,
                  width: 60,
              };
              this.tableColumn.push(p);
          }
      },
      async initOption() {
          if (typeof jsObj != "undefined") {
              var computeInfo = jsObj.GetComputeInfo();
              var arr = computeInfo.split("\r");
              if (arr.length == 3) {
                  this.macaddress = arr[0];
              }
          } else {
              this.macaddress = "Default";
          }
          try {
              const res = await this.$tool.request({
                  url: "LIS/LIS4/LIS410",
                  method: "post",
                  data: {
                      action: "initoption",
                  },
              });

              this.pattypeOption = res.pattypeOption;
              this.rescodeOption = res.rescodeOption;
              this.rptunitAll = res.rptunitAll;
              if (res.defrptunitid != 0) {
                  this.sel_rptunit = res.defrptunitid.toString();
              }
          } catch (e) {
              this.$message.warning(e);
          }
      },
      //全选/取消
      ChkAll(e) {
          if (this.tableData != null && this.tableData.length > 0) {
              this.tableData.forEach((item) => {
                  item.cp_selection = this.selectall == true ? "1" : "0";
              });
          }
      },
      TmpRClassName(row, column) {
          var stylestr = "padding:0 3px;";
          var nna = column.property.replace("col", "bgc");
          stylestr += "color:" + row[nna];
          return stylestr;
      },
      ChkEven(row) {
          row.cp_selection == "0" ? "1" : "0";
      },
      OpenMoreSel() {
          let mainheight = this.$refs.maindev.offsetHeight;
          this.Showflag = !this.Showflag;
          if (this.Showflag) {
              this.pagetopstyle.height = "190px";
              this.pagecenter.top = "195px";
              this.reportheight = mainheight - 195;
          } else {
              this.pagetopstyle.height = "97px";
              this.pagecenter.top = "102px";
              this.reportheight = mainheight - 102;
          }
      },
      //选择正常
      bTNcheckNormal() {
          this.tableData.forEach((e) => {
              e.cp_selection = "0";
              if (!["E", "Q", "P", "L", "H", "I"].includes(e.result_flag)) {
                  e.cp_selection = "1";
              }
          });
      },
      btnCalculate(flag) {
          if (flag == 0) {
              this.del1sd = 0;
              this.del2sd = 0;
              this.del3sd = 0;
              this.bCalcDlg = true;
              var numarr = [];
              //获取勾选结果数值
              for (var i = 0; i < this.tableData.length; i++) {
                  if (this.tableData[i].cp_selection == "1" && !XE.isNull(this.tableData[i].result_num) && this.tableData[i].result_num != "") {
                      numarr.push(parseFloat(this.tableData[i].result_num));
                  }
              }
              this.Calculate(numarr);
          } else {
              this["del" + flag + "sd"]++;
              if (this.calcParam.numarr.length > 0) {
                  var newarr = [];
                  this.numsdarr.forEach((e) => {
                      // console.log("🐮🍺Kanpai~e.result-e.sd",e.result+"-"+e.sd)
                      if (flag == 1 && e.sd <= 1) {
                          newarr.push(e.result);
                      } else if (flag == 2 && e.sd <= 2) {
                          newarr.push(e.result);
                      } else if (flag == 3 && e.sd <= 3) {
                          newarr.push(e.result);
                      }
                  });
                  this.Calculate(newarr);
              }
          }
      },
      Calculate(numarr) {
          this.calcParam = {};
          this.calcTableData = [];
          if (numarr.length > 0) {
              //41
              //?计算平均值
              var avg = XE.mean(numarr).toFixed(2);
              //?计算个数
              var cnt = numarr.length;
              //?计算标准差SD
              var temparr = []; //用来存储每个数组元素与平均值的差的平方。
              for (var i = 0; i < cnt; i++) {
                  var dev = parseFloat(numarr[i]).toFixed(2)-avg; //计算数组元素与平均值的差
                  temparr[i] = Math.pow(dev, 2); //计算差的平方
              }
              var powSum = 0; //存储差的平方总和
              for (var j = 0; j < temparr.length; j++) {
                  if (temparr[j].toString() != "" || temparr[j].toString() != null) {
                      powSum = parseFloat(powSum) + parseFloat(temparr[j].toString()); //计算差的平方总和
                  }
              }
              var sd = Math.sqrt(parseFloat(powSum) / parseFloat(cnt)).toFixed(2); //用差的平方总和除以数组长度即可得到标准差
              //?计算CV
              var cv = "";
              if (avg != "") {
                  cv = (sd / avg).toFixed(4);
              }
              //?计算最大值
              var max = XE.max(numarr);
              //?计算最小值
              var min = XE.min(numarr);
              //?计算中位数
              var sortarr = XE.sortBy(numarr); //原生的sort函数有点问题 认不清小数点
              var mid = "";
              if (cnt % 2 === 0) {
                  //偶数
                  var midr = parseFloat(cnt / 2);
                  var midl = midr - 1;
                  var a = sortarr[midl];
                  var b = sortarr[midr];
                  mid = parseFloat((a + b) / 2).toFixed(2);
              } else {
                  //奇数
                  mid = parseFloat(sortarr[(cnt + 1) / 2 - 1].toFixed(2));
              }

              //?计算百分比对应数
              this.calcParam = {
                  numarr: numarr,
                  item: this.tableData[0].rpt_itemname,
                  cnt: cnt,
                  avg: avg,
                  sd: sd,
                  cv: cv,
                  max: max,
                  min: min,
                  mid: mid,
                  p0001: this.getnum("percent", sortarr, cnt, 0.01),
                  p0100: this.getnum("percent", sortarr, cnt, 1),
                  p0250: this.getnum("percent", sortarr, cnt, 0.25),
                  p0500: this.getnum("percent", sortarr, cnt, 5),
                  p1000: this.getnum("percent", sortarr, cnt, 10),
                  p2000: this.getnum("percent", sortarr, cnt, 20),
                  p2500: this.getnum("percent", sortarr, cnt, 25),
                  p7500: this.getnum("percent", sortarr, cnt, 75),
                  p8000: this.getnum("percent", sortarr, cnt, 80),
                  p9000: this.getnum("percent", sortarr, cnt, 90),
                  p9500: this.getnum("percent", sortarr, cnt, 95),
                  p9750: this.getnum("percent", sortarr, cnt, 97.5),
                  p9900: this.getnum("percent", sortarr, cnt, 99),
                  p9990: this.getnum("percent", sortarr, cnt, 99.9),
              };
              this.numsdarr = [];
              //?开始给表格赋值
              for (var i = 0; i < numarr.length; i++) {
                  var colnum = 0;
                  var rownum = 0;
                  var tempobj = {
                      // sd: parseFloat((parseFloat(numarr[i]).toFixed(2) / parseFloat(avg).toFixed(2)).toFixed(2)),
                      sd:Math.abs((parseFloat((parseFloat(numarr[i]).toFixed(2) - parseFloat(avg).toFixed(2)).toFixed(2)))/ parseFloat(sd).toFixed(2)),
                      result: numarr[i],
                  };
                  this.numsdarr.push(tempobj);
                  if (i < 10) {
                      colnum = i;
                  } else {
                      var nsi = i.toString();
                      colnum = parseInt(nsi.substring(nsi.length - 1));
                      rownum = parseInt(nsi.substring(0, nsi.length - 1));
                  }
                  if (colnum == 0) {
                      this.calcTableData.push({});
                  }
                  this.calcTableData[rownum]["col_" + colnum] = parseFloat(numarr[i]);
                  this.calcTableData[rownum]["sd_" + colnum] =Math.abs((parseFloat((parseFloat(numarr[i]).toFixed(2) - parseFloat(avg).toFixed(2)).toFixed(2)))/ parseFloat(sd).toFixed(2));
                  //显示底色
                  // console.log("🐮🍺Kanpai~sd", this.calcTableData[rownum]["col_" + colnum]+"-"+this.calcTableData[rownum]["sd_" + colnum])
                  if (this.calcTableData[rownum]["sd_" + colnum] <= 1) {
                      this.calcTableData[rownum]["bgc_" + colnum] = "#000000";
                  } else if (this.calcTableData[rownum]["sd_" + colnum] <= 2) {
                      this.calcTableData[rownum]["bgc_" + colnum] = "rgb(43, 124, 216)";
                  } else if (this.calcTableData[rownum]["sd_" + colnum] <= 3) {
                      this.calcTableData[rownum]["bgc_" + colnum] = "#FF8000";
                  } else {
                      this.calcTableData[rownum]["bgc_" + colnum] = "rgb(240, 70, 48)";
                  }
              }
          }
      },
      getnum(type, arr = [], cnt = 0, x1 = "", x2 = "", x3 = "") {
          //type:mid,arrx:计算公式所需数值
          if (arr.length > 0 && cnt > 0) {
              //基于有数据才可以计算
              if (type == "percent" && x1 != "") {
                  var tempnum = cnt * x1 * 0.01;
                  var index = XE.toInteger(tempnum);
                  if (index > cnt - 1) {
                      index = cnt - 1;
                  }
                  return arr[index];
              } else return -1;
          } else return -1;
      },
      //查询
      btnQuery() {
          if (this.searchParam.rpt_itemcode == "") {
              this.$alert("请您先选择报告项目。", "提示");
              return false;
          }
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS661",
                  method: "post",
                  data: {
                      action: "query",
                      ...this.searchParam,
                      macaddress: this.macaddress,
                  },
              })
              .then((res) => {
                  if (res.dt.length > 0) {
                      this.tableData = res.dt;
                  } else {
                      this.tableData = [];
                  }
                  this.loading = false;
              })
              .catch((e) => {
                  this.loading = false;
              });
      },
      btnExc() {
          let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "LIS661");
          this.$parent.$refs.itemtags.tagsList.splice(index, 1);
          this.$router.go(-1);
      },
      currentChangeEvent({ row }) {
          this.selrow = row;
      },
      format({ row, column, cellValue }) {
          if (column.property == "charge_flag") {
              if (cellValue == "0") {
                  return "未计价";
              } else if (cellValue == "1") {
                  return "已计价";
              } else if (cellValue == "8") {
                  return "等待退费";
              } else if (cellValue == "9") {
                  return "已退费";
              } else if (cellValue == "5") {
                  return "免费";
              } else {
                  return "";
              }
          } else if (column.property == "reqtype") {
              if (cellValue == "C") {
                  return "检验";
              } else {
                  return "输血";
              }
          } else if (column.property == "emer_flag") {
              if (cellValue == "1") {
                  return "急";
              } else {
                  return "";
              }
          }
      },
      rowClassName({ row, rowIndex }) {
          if (row.req_stat == "1") {
              return "req_stat1";
          } else if (row.req_stat == "2") {
              return "req_stat2";
          } else if (row.req_stat == "3") {
              return "req_stat3";
          } else if (row.req_stat == "4") {
              return "req_stat4";
          } else if (row.req_stat == "5") {
              return "req_stat5";
          } else if (row.req_stat == "6") {
              return "req_stat6";
          } else if (row.req_stat == "8") {
              return "req_stat8";
          } else if (row.req_stat == "9") {
              return "reqstat9";
          } else {
              return "";
          }
      },
      cellClassName({ column, row }) {
          if (column.property == "emer_flag") {
              if (row.emer_flag == "1") {
                  return "col-red";
              } else {
                  return "";
              }
          }
      },
      xTableDblEvent({ row, rowIndex, $rowIndex, column }) {
          if (column.property == "chargefailmsg" && row.chargefailmsg && row.chargefailmsg != null) {
              // 弹窗显示字段信息
              this.$alert(row.chargefailmsg, "计价相关信息或失败相关信息", {
                  confirmButtonText: "确定",
                  callback: (action) => {},
              });
          }
      },
      setExportColumn() {
          let allColumnList = [];
          this.$refs.xTable.getColumns().forEach((element) => {
              if (element.property) {
                  allColumnList.push({
                      title: element.title,
                      property: element.property,
                  });
              }
          });
          this.allTableCol = allColumnList;
          this.chooseColumndialogVisible = true;
      },
      saveExportColumn() {
          this.chooseColumndialogVisible = false;
      },
      rptunitChange(code, name) {
          this.searchParam.rptunitid = code;
          this.rptunitname = name;
      },
      rptitemChange(code, name) {
          this.searchParam.rpt_itemcode = code;
          this.rpt_itemname = name;
      },
      pattypeChange(code, name) {
          this.searchParam.pat_typecode = code;
          this.pattypename = name;
      },
      specimenChange(code, name) {
          this.searchParam.specimen_code = code;
          this.specimenname = name;
      },
      reqwardChange(code, name) {
          this.searchParam.req_wardno = code;
          this.reqwardname = name;
      },
      reportuserChange(code, name) {
          this.searchParam.report_user = code;
          this.reportusername = name;
      },
      reqdocChange(code, name) {
          this.searchParam.req_docno = code;
          this.reqdocname = name;
      },
      instrChange(code, name) {
          this.searchParam.instrid = code;
          this.instrname = name;
      },
      btnExport() {
          var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
          let tableColumn = this.$refs.xTable.getColumns();
          let exportColumn = [];
          if (rightlocalStorage && rightlocalStorage.length > 0) {
              rightlocalStorage.forEach((item) => {
                  exportColumn.push({
                      title: item.extitle ? item.extitle : item.title,
                      field: item.property,
                  });
              });
          } else {
              tableColumn.forEach((item) => {
                  exportColumn.push({ title: item.title, field: item.property });
              });
          }
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcel(this.tableData, exportColumn, "LIS661 学术统计信息.xlsx", filtertxt, "统计条件：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "报告日期:" + XE.toDateString(this.searchParam.startdt, "yyyy-MM-dd") + "至" + XE.toDateString(this.searchParam.enddt, "yyyy-MM-dd") + "; ";
          if(this.searchParam.rptunitid) filtertxt += "报告单元:" + this.rptunitname+ "; ";
          if(this.searchParam.rpt_itemcode) filtertxt += "报告项目:" + this.rpt_itemname + "; ";
          if(this.searchParam.result_min || this.searchParam.result_max)  "检验结果:" + this.searchParam.result_min + "至" + this.searchParam.result_max+ "; ";
          if(this.searchParam.pat_name)  filtertxt += "姓名:" + this.searchParam.pat_name + "; ";
          if(this.searchParam.pat_name_mh) filtertxt += "姓名模糊查询; ";
          if(this.searchParam.pat_typecode) filtertxt += "病人类型:" + this.pattypename+ "; ";
          if (this.searchParam.pat_sex) filtertxt += "性别:" + (this.searchParam.pat_sex == "1" ? "男" : this.searchParam.pat_sex == "2" ? "女" : "全部") + "; ";
          if(this.searchParam.agemin || this.searchParam.agemax)  "年龄:" + this.searchParam.agemin + "至" + this.searchParam.agemax+ "; ";
          if (this.searchParam.rechkflag) filtertxt += "审核状态:" + (this.searchParam.rechkflag == "0" ? "未审核" : this.searchParam.rechkflag == "1" ? "已审核" : "全部") + "; ";
          if(this.searchParam.sampleno) filtertxt += "样本号:" + this.searchParam.sampleno+ "; ";
          if(this.searchParam.specimen_code) filtertxt += "样本类型:" + this.specimenname+ "; ";
          if(this.searchParam.result_txt) filtertxt += "专家评语模糊查询:" + this.searchParam.result_txt+ "; ";
          if(this.pat_sex_outflag) filtertxt += "无性别; ";
          if(this.pat_name_outflag) filtertxt += "无姓名; ";
          if(this.pat_sex_outflag) filtertxt += "正常结果; ";
          if(this.searchParam.req_wardno) filtertxt += "病区:" + this.reqwardname+ "; ";
          if(this.searchParam.report_user) filtertxt += "检验医生:" + this.reportusername+ "; ";
          if(this.searchParam.req_docno) filtertxt += "申请医生:" + this.reqdocname+ "; ";
          if(this.searchParam.instrid) filtertxt += "仪器:" + this.instrname+ "; ";
          if(this.searchParam.pat_diag) filtertxt += "临床诊断模糊查询:" + this.searchParam.pat_diag+ "; ";
          if(this.searchParam.report_comm) filtertxt += "备注模糊查询:" + this.searchParam.report_comm+ "; ";
          return filtertxt;
      },
  },
};
</script>

<style scoped>
::v-deep.vxe-input--wrapper .vxe-input {
  height: auto;
  width: 200px;
  border-radius: 0px;
}
::v-deep.el-button--default.btn-custom-cancel {
  float: right !important;
  margin-left: 10px;
}

.pagetop {
  left: 0;
  right: 0;
  height: 215px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  overflow-x: auto;
  white-space: nowrap;
}

.chargeflag {
  padding: 0px 10px;
}

.pagecenter {
  position: absolute;
  top: 134px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  right: 0;
  left: 0;
  height: 100%;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
::v-deep.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}
::v-deep.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
::v-deep.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 130px;
}
::v-deep .chargeflag .el-radio {
  margin-right: 10px !important;
}
::v-deep .chargeflag .el-radio__label {
  width: 35px;
  display: inline-block;
}
::v-deep .vxe-table .vxe-body--column.col-red {
  color: red;
}
::v-deep .vxe-table .vxe-body--column.sd1color {
  background-color: #FF8000;
}
::v-deep .vxe-table .vxe-body--column.sd2color {
  background-color: rgb(25, 57, 201);
}
::v-deep .vxe-table .vxe-body--column.sd3color {
  background-color: rgb(240, 70, 48);
}
::v-deep .vxe-table .vxe-body--row.row--current {
  background-color: #b6e8ff !important;
}
::v-deep .middle-center .vxe-table {
  height: 100%;
}
::v-deep .middle-center .vxe-table--body-wrapper {
  /* height: calc(100% - 54px) !important; */
  height: 100%;
}
::v-deep .el-textarea__inner {
  background-color: #a3c1f429;
  padding: 3px 5px;
}
::v-deep .el-divider__text.is-left {
  padding-left: 3px;
  font-weight: bold;
  font-size: 16px;
  left: 0;
  color: #000;
  transform: translateY(-50%);
}
::v-deep .el-input__inner[ismh="1"] {
  /* background-color: #a3c1f429; */
}
::v-deep .ismh1 .el-input__inner {
  background-color: #a3c1f429;
}
</style>